class Solution:
    def lexicalOrder(self, n: int):
        if n <= 0:
            return []
        r = []
        a = 1
        carry = False
        while a:
            if a <= n:
                r.append(a)
            else:
                carry = True
            if not carry:
                if a * 10 <= n:
                    a = a * 10
                    continue
                if a%10 == 9:
                    carry = True
                else:
                    a = a + 1
            while carry:
                a = a // 10
                if a == 0:
                    break
                if a % 10 == 9:
                    carry = True
                else:
                    a = a + 1
                    carry = False
        return r



if __name__ == '__main__':
    so = Solution()
    s = 100
    r = so.lexicalOrder(s)
    print(r)
